package com.Sep_Three;

import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

public class Solution515 {

    public static List<Integer> largestValues(TreeNode root) {
        List<Integer> res=new ArrayList<>();
        if (root==null) return res;
        Deque<TreeNode> deque=new LinkedList<>();
        deque.offer(root);
        while (!deque.isEmpty())
        {
            int size=deque.size();
            int temp=Integer.MIN_VALUE;
            for (int i=0;i<size;i++)
            {
                TreeNode node=deque.pollFirst();
                System.out.println(node.val);
                temp=Math.max(temp,node.val);
                if (node.left!=null) deque.offer(node.left);
                if (node.right!=null) deque.offer(node.right);
            }
            res.add(temp);
        }
        return res;
    }

    public static void main(String[] args) {

    }

     public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
    }
}
